package com.example.demo.controller.front;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/front")
public class FrontPageController {


    @RequestMapping("/index")
    public String index(Model model){
        model.addAttribute("index","selected");
        return "/front/index";
    }

    @RequestMapping("/about")
    public String about(Model model){
        model.addAttribute("about","selected");
        return "/front/aboutus";
    }

    @RequestMapping("/cases")
    public String cases(Model model){
        model.addAttribute("cases","selected");
        return "/front/cases";
    }

    @RequestMapping("/contact")
    public String contact(Model model){
        model.addAttribute("contact","selected");
        return "/front/contact";
    }
    @RequestMapping("/cases/detail/{id}")
    public String detail(@PathVariable Integer id, Model model){
        model.addAttribute("detail","selected");
        model.addAttribute("cId",id);
        return "/front/details";
    }

    @RequestMapping("/service")
    public String service(Model model){
        model.addAttribute("service","selected");
        return "/front/service";
    }

    @RequestMapping("/team")
    public String team(Model model){
        model.addAttribute("team","selected");
        return "/front/team";
    }
    @RequestMapping("/news")
    public String news(Model model){
        model.addAttribute("news","selected");
        return "/front/news";
    }
    @RequestMapping("/newsDetail/{id}")
    public String newsDetail(@PathVariable Integer id, Model model){
        model.addAttribute("newsDetail","selected");
        model.addAttribute("newsId",id);
        return "/front/New_details";
    }

    @RequestMapping("/login")
    public String login(){
        return "/login/login";
    }

    @RequestMapping("/logout")
    public String logout(HttpServletRequest request){
        request.getSession().removeAttribute("user");
        return "redirect:/front/login";
    }

}
